package top.huxy.boot.controller.admin;

import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.huxy.boot.annotation.Master;
import top.huxy.boot.annotation.RequestRemake;
import top.huxy.boot.model.dto.Pager;
import top.huxy.boot.model.dto.Query;
import top.huxy.boot.model.entity.VisitLog;
import top.huxy.boot.service.impl.VisitLogServiceImpl;
import top.huxy.boot.util.obj.Result;

/**
 * @Classname VisitLogController
 * @Description VisitLogController
 * @Date 2021/9/17 9:07
 * @Created by huxy
 */
@RestController
@RequestMapping("/admin/visitLog")
public class VisitLogController {

    VisitLogServiceImpl visitLogService;

    public VisitLogController(VisitLogServiceImpl visitLogService) {
        this.visitLogService = visitLogService;
    }

    @GetMapping("/getVisitLogList")
    @RequestRemake("获取访客日志列表")
    @Master
    public Result getVisitLogList(Pager pager, Query query) {
        PageInfo<VisitLog> data = visitLogService.getVisitLogList(pager,query);
        return Result.success(data);
    }

    @GetMapping("/getVisitLogByRequestId")
    @RequestRemake("根据请求id获取访客日志")
    @Master
    public Result getVisitLogByRequestId(@Param("requestId")String requestId){
        VisitLog visitLog = visitLogService.getVisitLogByRequestId(requestId);
        if(visitLog==null){
            return Result.notFound("未找到信息，请尝试持久化访问日志");
        }else{
            return Result.success(visitLog);
        }
    }
}
